<template>
  <div class="container">
    <van-picker
      :default-index="localDate"
      :show-toolbar="true"
      title="性别"
      :columns="columns"
      @confirm="onConfirm"
      @cancel="$emit('close')"
      @change="onChange"
    />
  </div>
</template>

<script>
import { setUserProfile } from '@/api/user'
export default {
  methods: {
    async  onConfirm () {
      this.$toast.loading({
        message: '修改中...',
        forbidClick: true,
        duration: 0
      })
      try {
        await setUserProfile({ gender: this.localDate })
        this.$emit('input', this.localDate)
        this.$toast.success('修改成功')
      } catch (err) {
        this.$toast.fail('修改失败')
      }
      this.$emit('close')
    },
    onChange (picker, value, i) {
      this.localDate = i
    }
  },
  data () {
    return {
      localDate: this.value,
      columns: ['男', '女']
    }
  },
  props: {
    value: {
      type: [String, Number],
      required: true
    }
  }
}
</script>

<style lang="less" scoped>
.van-nav-bar {
  background: #ffffff !important;
}
.container {
  background: rgb(250, 250, 250);
  height: 100%;
}
</style>
